  // 封装所有Http 请求方法
const httpFn = function($http) {
    var methods = {
      call: function(type, url, params, data) {
        return $http({
          method: type,
          url: url,
          params: params,
          data: data
        })
          .then(methods.success, methods.error);
      },
      success: function(data) {
        if (data.data.code == 399995) {
          window.location.replace("http://localhost:8800/login/index.html#/");
        }
        return data;
      },
      error: function(data) {
        return data;
      },
      get: function(url, params) {
        return methods.call("GET", url, params);
      },
      put: function(url, data) {
        return methods.call("PUT", url, null, data);
      },
      postp: function(url, params) {
        return methods.call("POST", url, params);
      },
      post: function(url, data) {
        return methods.call("POST", url, null, data);
      },
      delete: function(url, data) {
        return methods.call("DELETE", url, data, null);
      },
    };
    return methods;
  };

export default httpFn;
